package com.authine.cloudpivot.ext.applicationservice;

import com.alibaba.cola.dto.RequestContext;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.ext.applicationservice.authority.RoleApi;
import com.authine.cloudpivot.ext.constants.AppConst;
import com.authine.cloudpivot.ext.constants.PlatformConst;
import com.authine.cloudpivot.ext.dto.system.ResourceDto;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName ResourceRefreshService
 * @Description: 刷新本地资源
 * @Author fj
 * @Date 2021/9/29
 * @Version V1.0
 **/
@Slf4j
public class ResourceRefreshService {
     private static final RoleApi roleApi = new RoleApi();
     static {
         // 设置登录信息，避免报错
         RequestContext.get().setCorpLoginId(PlatformConst.corpLoginId);
         RequestContext.get().setLoginId(PlatformConst.loginId);
         RequestContext.get().setLoginName(PlatformConst.loginName);
         log.info("RequestContext：{}", JSONObject.toJSONString(RequestContext.get()));

         ResourceDto resourceDto = new ResourceDto();
         resourceDto.setAppCode(AppConst.SYSTEM_MANAGEMENT);
         roleApi.refreshResource(resourceDto);

         // 清除登录信息
         RequestContext.clear();
     }
}
